package com.gm.wholesale.module.settlement.ui.tab;

import android.util.ArrayMap;
import android.view.ViewGroup;


import com.gm.commonlib.base.baseBean.BasePageData;
import com.gm.commonlib.base.baseui.baseListviewUI.BaseGridFragment;
import com.gm.commonlib.module.evenbus.EventMessage;
import com.gm.commonlib.network.HttpServicesHolder;
import com.gm.commonlib.util.numberUtils.DigitUtil;
import com.gm.wholesale.R;
import com.gm.wholesale.constant.Constant;
import com.gm.wholesale.module.evenbus.EventBusType;
import com.gm.wholesale.module.order.bean.OrderPayInfoBean;
import com.gm.wholesale.module.settlement.api.IReconciliationApi;
import com.gm.wholesale.module.settlement.bean.CustomerSettlementBean;

import java.util.HashMap;

import io.reactivex.Observable;

public   abstract class BaseTabFragment extends BaseGridFragment<CustomerSettlementBean, BasePageData<CustomerSettlementBean>> {
    public long mCustomerId;

    public void setCustomerId(long customerId) {
        mCustomerId = customerId;

    }

    @Override
    protected void onCreateContentBody(ViewGroup parent) {
        super.onCreateContentBody(parent);
        setBodybg(getResources().getColor(R.color.color_EEF0F6));
    }

    @Override
    public void initPullToRefreshListView() {
        super.initPullToRefreshListView();
        mGridView.setNumColumns(2);
        mGridView.setHorizontalSpacing(15);
        mGridView.setVerticalSpacing(15);
    }




    @Override
    protected HttpServicesHolder<?, BasePageData<CustomerSettlementBean>> getHttpServicesHolder(long index) {
        return new HttpServicesHolder<IReconciliationApi, BasePageData<CustomerSettlementBean>>() {
            @Override
            public Observable<BasePageData<CustomerSettlementBean>> getHttpObservable(IReconciliationApi api) {
                ArrayMap<String, Object> queryData = new ArrayMap<>();
                queryData.put("customerId", mCustomerId);
                //0不返回 1返回
                queryData.put("isReturnDetail",0);
                queryData.put("isReturnJournals",0);
                queryData.put("page",1);
                queryData.put("pageSize", Constant.DEFAULTPAGESIZE);
                //明细列表类型1订单2售后
                queryData.put("type", 1);
                queryData.put("status", getStatus());
                return api.getCustomerSettlementList(queryData);
            }
        };
    }
    public int getStatus(){
        return TabType.WAITE_TO_PAY;
    }

    public HashMap<String,Object> getPayData(OrderPayInfoBean payInfoBean,long version){
        HashMap<String, Object> data = new HashMap<>();
        data.put("payMent", payInfoBean.getPayment());
        data.put("payAmount", DigitUtil.parseDouble(payInfoBean.getPaidAmount()));
        data.put("discountAmount",  DigitUtil.parseDouble(payInfoBean.getDiscountAmount()));
        data.put("version", version);
        return data;
    }

    @Override
    public void onReceiveEvent(EventMessage event) {
        super.onReceiveEvent(event);
        if (event.getCode()== EventBusType.UPDATE_PAY_TAB_LIST.getType()){
            refreshData();
        }

    }
}



